<?php
/*
 * $Id$
 *
 *
 */

if (!defined('BASEPATH')) exit('No direct script access allowed');

class Verifica extends MX_Controller {
	var $template;
	function __construct()
	{
		parent::__construct();
        
        $this->user->require_login();
		
		$this->template['module'] = "adozioni";

	}
	
	function index()
	{
		$this->layout->load($this->template, 'configurazione_verifica_index');
		echo "verifica";
		
	}
	
    
	function cap()
	{
        
		$query = $this->db->query("SELECT s.id, s.nomecognome, s.cap FROM sostenitori s WHERE s.id_cod_invio IN (1, 10) AND s.attivo = 1 AND s.nazione ='Italia' AND  s.cap NOT IN (SELECT b.cap FROM cap_bacini b) ORDER BY LOWER(s.nomecognome)");
		if($query->num_rows() > 0)
		{
			$rows = $query->result_array();
			
			$this->template['rows'] = $rows;
			$this->template['title'] = "CAP da verificare";
			$this->layout->load($this->template, 'stampe_verifica_cap');
		}
		else
		{
			echo "Finito";
		}
		
	}
	
	function solocap()
	{
		$query = $this->db->query("SELECT DISTINCT s.cap FROM sostenitori s WHERE s.id_cod_invio IN (1, 10) AND s.attivo = 1 AND s.nazione ='Italia' AND  s.cap NOT IN (SELECT b.cap FROM cap_bacini b) ORDER BY s.cap");

		if($query->num_rows() > 0)
		{
			$rows = $query->result_array();
			
			$this->template['rows'] = $rows;
			$this->template['title'] = "CAP non esistente";
			$this->layout->load($this->template, 'stampe_verifica_solocap');
		}
		else
		{
			echo "Finito";
		}
		
	}
	
	function indirizzi_email()
	{
		$this->load->model('sostenitori_model', 'sos');
		$params = array('select' => 's.id, s.nomecognome as name, s.email', 'where' => "s.email <> '' AND (s.email LIKE '% %' OR s.email LIKE '%,%' OR s.email NOT LIKE '%@%')", 'group_by' => 's.id, nomecognome, email', 'order_by' => 'nomecognome');
		//$params = array('select' => 's.id, s.nomecognome as name, s.email', 'where' => "s.email NOT REGEXP '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$'", 'group_by' => 's.id, nomecognome, email', 'order_by' => 'nomecognome');
		$rows = $this->sos->get_list($params);
		

		if($rows)
		{
			
			$this->template['rows'] = $rows;
			$this->template['title'] = "Email da verificare";
			$this->layout->load($this->template, 'configurazione_verifica_indirizzo_email');
		
		}
		else
		{
			echo "finito";
		}
		
	
	}
}
